<%-- Copyright (c) 2002 BroadVision, Inc. All rights reserved              --%>
<%-- The product described in this manual may be protected by one or more  --%>
<%-- U.S. and International patents. The BroadVision One-To-One software   --%>
<%-- is covered by U.S. patent 5,710,887.                                  --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and the BroadVision logo are registered       --%>
<%-- trademarks, and BroadVision One-To-One is a trademark of BroadVision, --%>
<%-- Inc. IONA and Orbix are trademarks of IONA Technologies, Ltd. RSA,    --%>
<%-- MD5, and RC2 are trademarks of RSA Data Security, Inc. All other      --%>
<%-- trademarks, service marks, and trade names belong to their respective --%>
<%-- owners. BroadVision, Inc. disclaims any proprietary interest in the   --%>
<%-- marks and names of others.                                            --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<%@page import="java.util.Currency"%>
<%@page import="java.util.Locale"%>

<script language="javascript" src="<%=request.getContextPath()%>/mt/js/userPopup.js"></script>
<script language = "JavaScript" src ="<%=request.getContextPath()%>/demand/js/form_date_funcs.js "></script>
<script language="JavaScript" src="<%=request.getContextPath()%>/mc/js/date.js"></script>
<script language="JavaScript">
var back_count = -1;


function checkDate(yr, mn, dy) {
		if (yr == -1 || mn == -1 || dy == -1)
			return false;

    if (!isValidDate(yr, mn, dy)) {
    	return false;
    }
    return true;
	
}

// function to POST form parameters to a ".do"
function doAction(action, myform){

    if( validateForm( myform)) {
      myform.action = '<html:rewrite page="'+action+'" />'; 
      myform.submit();
    }
    return true;
}

function validateForm (form) {
 
   if (form.includeDateFrom.checked &&
       form.includeDateTo.checked)  {
     var dateFrom = getDateOnly("orderSearchForm","dateFrom");
     var dateTo = getDateOnly("orderSearchForm","dateTo");
     if (dateTo < dateFrom) {
       alert('<bean:message key="demand.order.search.javaScript.dateValidation" bundle="ss"/>');
       return false;
     }
  }  
  return true;
}

</script>     

<%
  String ctxPath = request.getContextPath();
  Currency locCurrency = Currency.getInstance(Locale.getDefault());
  String symbol = locCurrency.getSymbol();
%>

<html:form method="post" action="/demand/orderSearch.do">
<div>
<table width="100%" cellspacing="0" cellpadding="0" border="0" summary="Main body">
  <tr>
    <td width="100%" class="column2" valign="top">
     
    <table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="orders search">
        <tr>
        <td valign="top">
      <div class="pageTitle">
      	  <logic:equal name="orderSearchForm" property="showResults" value="false">
      		<bean:message bundle="ss" key="demand.order.label.title" />
      	  </logic:equal>
      	  <logic:equal name="orderSearchForm" property="showResults" value="true">
      		<bean:message bundle="ss" key="demand.order.label.title" />: 
      	  	<bean:write name="orderSearchForm" property="resultSize" />
      		<bean:message bundle="ss" key="demand.order.label.found" />
      	   </logic:equal>
      </div>
      <div class="errorMessage"><html:errors bundle="ss"/></div>
      <div><%@include file="/mc/common/pagetab.jsp"%></div>
      <input type=hidden name="doSearch" value="true">
      <input type=hidden name="userAlias" />
      <input type="hidden" name="useFullName" value="true" />
      <div class="pageSubtitle">
        <span class="left">Search criteria</span>
        <span class="right">
          &nbsp;
        </span>
      </div>
      
      <table class="labelForm" border="0" cellspacing="0" cellpadding="2" summary="order search" width="100%">
          <tr>
            <td class="label" width="15%">
            <bean:message bundle="ss" key="demand.order.label.submitterId" />:
            </td>
            <td class="labelField" width="85%" colspan="4">
            	<html:text name="orderSearchForm" property="submitterAlias" />    
            	<input type="button" name="btnAction"
            		value='<bean:message bundle="ss" key="button.search" /> ...'
        		class="pageButton" onClick="JavaScript:userSearchPopup(
        		'<html:rewrite page="/mt/userSearchPopup.do"/>','orderSearchForm','submitterAlias')" >
        	
            </td>
          </tr>          
          <tr>
	     <td class="label" width="15%" valign="top">
	          <bean:message bundle="ss" key="demand.order.label.orderState" />:
	     </td>
	     <td class="labelField" width="85%" colspan="4">
	        <bean:define id="states" name="orderSearchForm" property="orderStates"
			type="java.util.HashMap" /> 
	      	<html:select name="orderSearchForm" property="selectedOrderStates" 
	                                                  size="5" multiple="true" >
	      		<html:options collection="states" property="key" labelProperty="value"/>
	      	</html:select>
	     </td>
	  </tr>
	  <tr>
            <td class="label" width="15%">
            <bean:message bundle="ss" key="demand.order.label.productName" />:
            </td>
            <td class="labelField" width="85%" colspan="4">
    		<html:text name="orderSearchForm" property="productName"/>
            </td>
          </tr>
	  <tr>
            <td class="label" width="15%">
            <bean:message bundle="ss" key="demand.order.label.productID" />:
            </td>
            <td class="labelField" width="85%" colspan="4">
        	<html:text name="orderSearchForm" property="productId" />
            </td>
          </tr>
	  <tr>
            <td class="label" width="15%">
            <bean:message bundle="ss" key="demand.order.label.orderNumber" />:
            </td>
            <td class="labelField" width="85%" colspan="4">
		<html:text name="orderSearchForm" property="orderNumber" />
            </td>
          </tr>
	  <tr>
            <td class="label" width="15%">
            <bean:message bundle="ss" key="demand.order.label.totalAmount" />:
            </td>
            <td class="labelField" width="85%" colspan="4">
            	<bean:message bundle="ss" key="demand.order.label.totalFrom" />&nbsp;
            	<%=symbol%>
		<html:text name="orderSearchForm" property="amountFrom" />
		&nbsp;
		<bean:message bundle="ss" key="demand.order.label.totalTo" />&nbsp;
		<%=symbol%>
		<html:text name="orderSearchForm" property="amountTo" />
	    </td>
          </tr>
          <tr> 
	    <td class="label" width="20%">
		<bean:message key="demand.order.label.date" bundle="ss"/>:
	    </td>
	    <td class="labelField" width="10%" nowrap>
		<html:checkbox property="includeDateFrom"/>
		<bean:message key="demand.order.label.dateFrom" bundle="ss"/>
	    </td>
	    <td class="labelField" width="70%" nowrap>
		<bvhtml:date property="dateFrom"
			onChangeMonth="onChangeMonth"
			onChangeYear="onChangeYear"
			noblank="true"/>
		<a href="JavaScript:datePopup(
			'<html:rewrite page="/mc/calendar.do"/>',
			'orderSearchForm','dateFrom')">
		<img src="<%= ctxPath %>/mc/images/action/calendar.gif"
		 width="22" height="22"	alt='<bean:message key="image.alt.chooseDate" bundle="ss"/>'
		 title='<bean:message key="image.alt.chooseDate" bundle="ss"/>'
		 border="0" align="absmiddle"/></a>
	    </td>					
	</tr>
	<tr>
	     <td class="label" width="20%">&nbsp;</td>
	     <td class="labelField" width="10%" nowrap>
		<html:checkbox property="includeDateTo"/>
		<bean:message key="demand.order.label.dateTo" bundle="ss" />
	      </td>
	      <td class="labelField" width="70%" nowrap>
		 <bvhtml:date property="dateTo"
			onChangeMonth="onChangeMonth"
			onChangeYear="onChangeYear"
			noblank="true"/>
		<a href="JavaScript:datePopup(
			'<html:rewrite page="/mc/calendar.do"/>',
			'orderSearchForm','dateTo')">
			<img src="<%= ctxPath %>/mc/images/action/calendar.gif"
			width="22" height="22"
			alt='<bean:message key="image.alt.chooseDate" bundle="ss"/>'
			title='<bean:message key="image.alt.chooseDate" bundle="ss"/>'
			border="0" align="absmiddle"/></a>
	       </td>
       	</tr>
       	
     </table>       
        
           
        <div class="pageButtonWrap" align="right">
	    <html:hidden property="showResults" />
	    <input type="button" name="show" class="inputButton" 
	        onClick="this.form.showResults.value='true';doAction('/demand/orderSearch.do?actionSearch=true&show=1&pager.offset=0', this.form);"
	        value="<bean:message bundle="ss" key="demand.order.label.showResults"/>" />
	</div>    

	<br>
	<logic:equal name = "orderSearchForm" property = "showResults" value = "true">				
	<div class="pageSubtitle">
	<span class="left">
	    <bean:message bundle="ss" key="demand.order.label.searchResults"/> - 
	    <bean:write  name="orderSearchForm" property="resultSize"/>
	    <bean:message bundle="ss" key="demand.order.label.found" />
	</span>
        </div>
        
        <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Order list" width="100%">
          <tr class="listHeader">
            <th id="OrderNumber" align="left">
            	<bean:message bundle="ss" key="demand.order.label.orderNumber"/>
            </th>
            <th id="OrderState" align="left">
            	<bean:message bundle="ss" key="demand.order.label.orderState"/>
            </th>
            <th id="Submitter" align="left">
	         <bean:message bundle="ss" key="demand.order.label.submitter"/>
            </th>
     	    <th id="Date" align="left">
     	    	<bean:message bundle="ss" key="demand.order.label.date"/>
     	    </th>
            <th id="Total" align="left">
            	<bean:message bundle="ss" key="demand.order.label.totalAmount"/>
            </th>
          </tr>

    	  <c:if test="${not empty orderListView.map.orderSearchResult}">    
            <c:forEach var="item" items="${orderListView.map.orderSearchResult}" varStatus="index">
    		
                 <c:choose>
            	 <c:when test="${(index.count + 1) % 2 == 0}">
    	      		<tr class="listEven">
            	 </c:when> 
      	    	 <c:otherwise>
    	      		<tr class="listOdd">
    	      	 </c:otherwise>
      		 </c:choose> 
      		 
      		 <c:url var="viewUrl" value="/demand/orderDetail.do">
		      <c:param name="oNum" value="${item.map.orderNumber}"/>
		  </c:url>
      		 
      		 <td valign="top" headers="OrderNumber">
		      <a href='<c:out value="${viewUrl}"/>'>
		      <c:out value="${item.map.orderNumber}"/></a>
              	 </td>
              	 <td valign="top" headers="OrderState">
		 	<c:out value="${item.map.orderState}"/>
              	 </td>
              	 <td valign="top" headers="Submitter">
		 	<c:out value="${item.map.submitter}"/>
              	 </td>
              	 <td valign="top" headers="Date">
			<bean:write name="item" property="orderDate" formatKey="format.datetime.short" bundle="mc.messages"/>
              	 </td>
              	 <td valign="top" headers="Total">
              	 	<%=symbol%><c:out value="${item.map.orderTotal}"/>
              	 </td>
              	 
           </c:forEach>
	</c:if>
	<c:if test="${empty orderListView.map.orderSearchResult}">
	<tr class="listOdd"> 
	  <td colspan="5" valign="top" wrap class="label" width="40%" align="center"> 
		<bean:message bundle="ss" key="demand.order.label.noItems"/>
	   </td>
	</tr>
	</c:if>
	</table>
		        
        <c:if test="${not empty orderListView.map.orderSearchResult}">
		<%@ include file="/mc/common/pager.jsp" %>
	</c:if>
      </logic:equal>
     </tr>
     </table>

   </td>
 </tr>   
</table>

</div>
</html:form> 

